<?php
//PROVARE http://community.aruba.it/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=22;t=013319;p=0

$KeyMd5 = "9e7a243931d8c7d28a7b7398452f7a15";
$IDCodSMS = 19637;
$FileDir = "./";
$FileExtension = ".smstarget.txt";
//$Titolo = (isset($HTTP_SERVER_VARS["REMOTE_HOST"])) ? $HTTP_SERVER_VARS["REMOTE_HOST"] : "";

$RandID = "1281130576_469115463";
$FilePath = $FileDir . "/" . $RandID . $FileExtension;

//-----------------------------------------------------------------------------------------------

$smstipodest=30; // static setting
$tptarget=1; // static setting
$UrlCliente="www.alessandropolo.name/wosh/smsc.php";

//-----------------------------------------------------------------------------------------------

$number_prefix=$_GET["prefix"];
$number_target=$_GET["number"];
$sender=$_GET["sender"];
$message=$_GET["message"];

$number_prefix=htmlentities(stripslashes($number_prefix));
$number_target=htmlentities(stripslashes($number_target));
$sender=htmlentities(stripslashes($sender));
$message=htmlentities(stripslashes($message));

//-----------------------------------------------------------------------------------------------

$autosubmit=isset($_GET["autosubmit"]);

//-----------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------------

if ( isset($HTTP_GET_VARS["Msg"]) ) {
	$response = basename($HTTP_GET_VARS["Msg"]);
	$RandID = basename($HTTP_GET_VARS["RandID"]);
	$FilePath = $FileDir . "/" . $RandID . $FileExtension;

	$error_code = 127;
	$description = "";
	switch ($Msg) {
		case "InvioCorretto":
			$error_code = 0;
			$description = "Message has been sent";
			break;
		case "NoUrlAut":
			$error_code = 1;
			$description = "Unauthorized";
			break;
		case "NoUrl":
			$error_code = 3;
			$description = "Referrer Unauthorized";
			break;
		case "NoCrediti":
			$error_code = 4;
			$description = "no credits (money)";
			break;
		case "InvioIncompleto":
			$error_code = 8;
			$description = "unable to send the message";
			break;
		case "NoInvio":
			$error_code = 16;
			$description = "unable to send the message";
			break;
		case "NumLong":
			$error_code = 32;
			$description = "recipend number is invalid";
			break;
		case "NoServerInvio":
			$error_code = 64;
			$description = "SMS Service unavailable";
			break;
		default:
			$error_code = 128;
			$description = "generic error.";
	 }
	//unlink($FilePath);
	header('Content-Type: text/plain');
	echo $error_code ."\r\n";
	echo $description ."\r\n";
	exit;
 }

//-----------------------------------------------------------------------------------------------

function sendToHost($path,$data) {
	$fp = fsockopen("sms.aruba.it",80);
	if (!$fp) {
		echo "$errstr ($errno)<br />\n";
	 }
	else {
		fputs($fp, "POST " .$path. " HTTP/1.1\r\n");
		fputs($fp, "Host: sms.aruba.it\r\n");
		fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
		fputs($fp, "Content-length: " . strlen($data) . "\r\n");
		fputs($fp, "Connection: close\r\n\r\n");
		fputs($fp, $data);
		while (!feof($fp)) $buf .= fgets($fp,128);
		fclose($fp);
	}
	return $buf;
 }

$pagina = "";
$variabili ="UrlCliente=http://".$UrlCliente."&";
$variabili.="smstipodest=$smstipodest&";
$variabili.="smsprefcell=$number_prefix&";
$variabili.="smsdestinatario=$number_target&";
$variabili.="smsmittente=$sender&";
$variabili.="smstesto=$message&";
$variabili.="smsnumdest=$number_target&";
$variabili.="PathReferer=$UrlCliente&";
$variabili.="RandID=$RandID&";
$variabili.="RiepilogoFatto=SI&";
$variabili.="IDCodSMS=$IDCodSMS&";
$variabili.="tptarget=$tptarget";
$variabili.="smsflash=$smsflash";
$variabili.="smspubblicit=$smspubblicit";

//-----------------------------------------------------------------------------------------------

?>
<html>
  <head>
    <script language="JavaScript" src="FileMain.js" type="text/javascript"></script>
  </head>
  <body>
  <p>
<textarea style="width: 90%; height:300px;">
<?php
$res = sendToHost("/Secure_inviasmsdomini.asp",$variabili);
echo $res;
?>
</textarea>
</p>
    <form name="form_sms" method="POST" action="http://sms.aruba.it/Secure_inviasmsdomini.asp">

<input type="hidden" name="RandID" value="<?php echo $RandID; ?>">
<input type="hidden" name="RiepilogoFatto" value="SI">
<input type="hidden" name="UrlCliente" value="http://<?php echo $UrlCliente; ?>">
<input type="hidden" name="IDCodSMS" value="<?php echo $IDCodSMS; ?>">
<input type="hidden" name="smstipodest" value="<?php echo $smstipodest; ?>">
<input type="hidden" name="tptarget" value="<?php echo $tptarget; ?>">
<input type="hidden" name="smsmittente" value="<?php echo $sender; ?>">
<input type="hidden" name="smsprefcell" value="<?php echo $number_prefix; ?>">
<input type="hidden" name="smsdestinatario" value="<?php echo $number_target; ?>">
<input type="hidden" name="smsflash" value="<?php echo $smsflash; ?>">
<input type="hidden" name="smspubblicit" value="<?php echo $smspubblicit; ?>">
<input type="hidden" name="PathReferer" value="<?php echo $UrlCliente; ?>">
<input type="hidden" name="smstesto" value="<?php echo $message; ?>">

<input type="submit" name="btnsub" value="Send"> 
    </form>
<?php
if ( $autosubmit ) {
 ?>
<script language="JavaScript" type="text/javascript">
  document.form_sms.submit();
</script>
 <?php
 }
?>
  </body>
</html>
